import Vue from 'vue';
import Router from 'vue-router';

/* layout */
import Layout from '../views/layout/Layout';

/* login */
import Login from '../views/login/';
const authRedirect = resolve => require(['../views/login/authredirect'], resolve);
const sendPWD = resolve => require(['../views/login/sendpwd'], resolve);
const reset = resolve => require(['../views/login/reset'], resolve);

/* home */
const home = resolve => require(['../views/home/index'], resolve);

/* Introduction */
const Introduction = resolve => require(['../views/introduction/index'], resolve);

/* error page */
const Err404 = resolve => require(['../views/error/404'], resolve);
const Err401 = resolve => require(['../views/error/401'], resolve);
const error = resolve => require(['../views/error/serverMaintenance'], resolve);

/* error log */
const ErrorLog = resolve => require(['../views/errlog/index'], resolve);

/* theme  */
const Theme = resolve => require(['../views/theme/index'], resolve);

const logiLayout = resolve => require(['../views/layout/logiLayout'], resolve);


// 公告栏
const noticeList = resolve => require(['../views/home/comps/noticeList'], resolve);
const messageList = resolve => require(['../views/home/comps/messageList'], resolve);
const newsDetail = resolve => require(['../views/home/comps/newsDetail'], resolve);

// 学校管理
const schoolManages = resolve => require(['../views/schoolManage/schoolManages'], resolve);
const leaderInfo = resolve => require(['../views/schoolManage/leaderInfo'], resolve); // 负责人详情  
const addSchool = resolve => require(['../views/schoolManage/addSchool'], resolve); // 添加学校信息
const modifySchool = resolve => require(['../views/schoolManage/modifySchool'], resolve); // 修改学校信息


// 服务管理
const serviceConfig = resolve => require(['../views/serviceManage/serviceConfig'], resolve);
const serviceOrder = resolve => require(['../views/serviceManage/serviceOrder'], resolve);
const flowChart = resolve => require(['../views/serviceManage/comps/flowChart'], resolve);
const newService = resolve => require(['../views/serviceManage/comps/newService'], resolve);
const getService = resolve => require(['../views/serviceManage/comps/getService'], resolve);
const orderStatistics = resolve => require(['../views/serviceManage/comps/orderStatistics'], resolve);
const schoolStatistics = resolve => require(['../views/serviceManage/comps/schoolStatistics'], resolve);
const orderDetails = resolve => require(['../views/serviceManage/comps/orderDetails'], resolve);

//卡券管理
const cardDetails = resolve => require(['../views/cardCoupons/cardDetails'], resolve); //卡券服务
const cardExtend = resolve => require(['../views/cardCoupons/cardExtend'], resolve); //查看详情
const cardToBuy = resolve => require(['../views/cardCoupons/cardToBuy'], resolve); //卡券购买
const cardBuyRecord = resolve => require(['../views/cardCoupons/cardBuyRecord'], resolve); //卡券购买记录
const cardExtendRcord = resolve => require(['../views/cardCoupons/cardExtendRcord'], resolve); //卡券发放记录
const cardExtendCheck = resolve => require(['../views/cardCoupons/cardExtendCheck'], resolve); //查看发放记录
const cardExplain = resolve => require(['../views/cardCoupons/cardExplain'], resolve); //卡券说明
const buyCheckDetail = resolve => require(['../views/cardCoupons/comps/buyCheckDetail'], resolve); //查看卡券购买详情

// const cardToExtend = resolve => require(['../views/cardCoupons/cardToExtend'], resolve); //卡券发放选择

//会员管理 
const memberOrder = resolve => require(['../views/vipManagement/memberOrder'], resolve); //会员管理
const otherOrder = resolve => require(['../views/vipManagement/otherOrder'], resolve); //其他管理
const codeManage = resolve => require(['../views/vipManagement/codeManage'], resolve); //查看账户
const checkvipDetails = resolve => require(['../views/vipManagement/checkDetails'], resolve); //查看明细
const packingOrder = resolve => require(['../views/vipManagement/packingOrder'], resolve);//会员打包订单
const packingOrderDetail = resolve => require(['../views/vipManagement/packingOrderDetail'], resolve);//会员打包订单详情

//账户管理 
const accountMangement = resolve => require(['../views/accountManagement/accountMangement'], resolve); //账户管理
const makeAccount = resolve => require(['../views/accountManagement/makeAccount'], resolve); //填写账户
const accountDetail = resolve => require(['../views/accountManagement/accountDetail'], resolve); //查看账户
const checkDetails = resolve => require(['../views/accountManagement/checkDetails'], resolve); //查看明细
const review = resolve => require(['../views/accountManagement/comps/review'], resolve); //审核中


// 广告管理
const operation = resolve => require(['../views/operationManagement/AdvMangement/index'], resolve); // 广告管理
const parcelMangement = resolve => require(['../views/operationManagement/AdvMangement/comps/parcelMangement'], resolve); // 广告统一管理
const getImgState = resolve => require(['../views/operationManagement/AdvMangement/comps/getImgState'], resolve); // 查看状态
const advDisplay = resolve => require(['../views/operationManagement/AdvMangement/comps/advDisplay'], resolve); // 查看广告
const editAdv = resolve => require(['../views/operationManagement/AdvMangement/comps/editAdv'], resolve); // 编辑广告

// 权限管理
const authorityComponent = resolve => require(['../views/systemManage/authorityManagement'], resolve);
const addAuthority = resolve => require(['../views/systemManage/authorityManagement/addAuthor'], resolve);
const editAuthority = resolve => require(['../views/systemManage/authorityManagement/editAuthor'], resolve);
const showAuthority = resolve => require(['../views/systemManage/authorityManagement/showAuthor'], resolve);

//用户信息
const userInof = resolve => require(['../views/userManage/userInof'], resolve);
const newUser = resolve => require(['../views/userManage/comps/newUser'], resolve);
const modifi = resolve => require(['../views/userManage/comps/modifi'], resolve);

// 统计报表
const totalTrend = resolve => require(['../views/reportForms/totalTrend'], resolve); // 总体趋势
const schoolStatic = resolve => require(['../views/reportForms/schoolStatic'], resolve); // 学校用户统计
const classStatic = resolve => require(['../views/reportForms/classStatic'], resolve); // 班级用户统计
const teacherActivity = resolve => require(['../views/reportForms/teacherActivity'], resolve); // 教师活跃度
const parentActivity = resolve => require(['../views/reportForms/parentActivity'], resolve); // 家长活跃度
const studentActivity = resolve => require(['../views/reportForms/studentActivity'], resolve); // 学生活跃度

//  考勤设备
const attendance = resolve => require(['../views/attendanceMain/attendance'], resolve);
const getAttendance = resolve => require(['../views/attendanceMain/getAttendance'], resolve); //查看考勤设备

//  卡片管理
const cardMain = resolve => require(['../views/cardMainmanagement/cardMain'], resolve);

// 修改密码
const modifyPass = resolve => require(['../views/userManage/modifyPass'], resolve);

Vue.use(Router);


/**
 * icon : the icon show in the sidebar
 * hidden : if hidden:true will not show in the sidebar
 * redirect : if redirect:noredirect will not redirct in the levelbar
 * noDropdown : if noDropdown:true will not has submenu
 * meta : { role: ['admin'] }  will control the page role
 **/

export const constantRouterMap = [
    { path: '/login', component: Login, hidden: true },
    { path: '/authredirect', component: authRedirect, hidden: true },
    { path: '/sendpwd', component: sendPWD, hidden: true },
    { path: '/reset', component: reset, hidden: true },
    {
        path: '/userManage/modifyPass',
        name: '修改密码',
        hidden: true,
        component: modifyPass
    },
    {
        path: '/404',
        component: Layout,
        redirect: '/404/index',
        hidden: true,
        children: [
            { path: 'index', component: Err404 }
        ]
    },
    // { path: '/404', component: Err404, hidden: true },
    { path: '/401', component: Err401, hidden: true },
    { path: '/error', component: error, hidden: true },
    {
        path: '/',
        component: Layout,
        redirect: '/home/index',
        name: '首页',
        hidden: true,
        children: [{ path: 'home', component: home }]
    }
]

export default new Router({
    // mode: 'history', //后端支持可开
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRouterMap
});

export const homeRouterMap = [{
        path: '/',
        redirect: '/home',
        hidden: true
    },
    {
        path: '/home',
        component: Layout,
        redirect: '/home/index',
        name: '公告栏',
        icon: 'zujian',
        noDropdown: true,
        meta: {
            cache: 'noticeList,messageList'
        },
        children: [
            { path: 'index', component: home },
            { path: 'noticeList', component: noticeList, name: '公告列表' },
            { path: 'messageList', component: messageList, name: '资料文档' },
            { path: 'newsDetail/:state?/:id?', component: newsDetail, name: '资讯详情' }
        ]
    },
    {
        path: '/userManage',
        redirect: 'userManage/userInof',
        component: Layout,
        icon: 'xinrenzhinan',
        name: "员工管理",
        noDropdown: true,
        meta: {
            cache: 'userInof'
        },
        children: [
            { path: 'userInof', component: userInof },
            { path: 'newUser', component: newUser, name: '添加员工' },
            { path: 'modifi/:id', component: modifi, name: '修改员工' }
        ]
    },
    // 学校管理
    {
        path: '/schoolManage',
        component: Layout,
        name: '学校管理',
        icon: 'tubiaoleixingzhengchang',
        noDropdown: true,
        redirect: '/schoolManage/schoolManages',
        meta: {
            cache: 'schoolManages'
        },
        children: [
            { path: 'schoolManages', component: schoolManages },
            { path: 'leaderInfo/:pId', component: leaderInfo, name: '负责人信息' },
            { path: 'addSchool', component: addSchool, name: '添加学校' },
            { path: 'modifySchool/:pId', component: modifySchool, name: '修改学校信息' }
        ]
    },
    // 服务管理
    {
        path: '/serviceOrder',
        component: Layout,
        redirect: '/serviceOrder/orderStatistics',
        name: '服务管理',
        icon: 'theme',
        noDropdown: false,
        meta: {
            cache: 'schoolStatistics,orderDetails,serviceConfig'
        },
        children: [{
                path: '/serviceOrder',
                component: logiLayout,
                redirect: '/serviceOrder/orderStatistics',
                name: '服务订单',
                noDropdown: false,
                children: [
                    { path: 'orderStatistics', component: orderStatistics, name: '订单统计' },
                    { path: 'schoolStatistics', component: schoolStatistics, name: '学校统计' },
                    { path: 'orderDetails', component: orderDetails, name: '订单明细' }
                ]
            },
            {
                path: '/serviceContent',
                component: logiLayout,
                redirect: '/serviceContent/serviceConfig',
                name: '服务配置',
                noDropdown: true,
                children: [
                    { path: 'serviceConfig', component: serviceConfig },
                    { path: 'flowChart', component: flowChart, name: '服务开通说明' },
                    { path: 'newService/:state?/:obj?/:add?/:sMoney?/:sSchoolName?/:sServiceName?/:fSchoolId?/:fServiceId?', component: newService, name: '服务开通' },
                    { path: 'getService/:id/:fServiceId', component: getService, name: '查看服务' }
                ]
            }
        ]
    },

    {
        path: '/cardCoupons',
        component: Layout,
        redirect: '/cardCoupons/service',
        name: '卡券管理',
        icon: 'tuozhuai',
        noDropdown: false,
        meta: {
            cache: 'cardDetails,cardBuyRecord,cardExtendRcord'
        },
        children: [{
                path: '/cardCoupons/service',
                component: logiLayout,
                redirect: 'service/list',
                name: '卡券服务',
                noDropdown: true,
                children: [
                    { path: 'list', component: cardDetails },
                    { path: 'explain', component: cardExplain, name: '卡券说明' },
                    // { path: 'cardToExtend', component: cardToExtend, name: '卡券发放选择' },
                    { path: 'extend/:schoolId?/:serviceId?/:sSchoolName?/:sServiceName?', component: cardExtend, name: '查看详情' },
                    { path: 'cardBuy/:schoolId/:serviceId', component: cardToBuy, name: '卡券购买' }
                ]
            },
            // { path: 'buyRecord', component: cardBuyRecord, name: '卡券购买记录' },
            {
                path: '/cardCoupons/buyRecord',
                component: logiLayout,
                redirect: 'buyRecord/buyRecord',
                name: '卡券购买记录',
                noDropdown: true,
                children: [
                    { path: 'buyRecord', component: cardBuyRecord },
                    { path: 'buyCheckDetail/:pId', component: buyCheckDetail, name: '查看购买详情' },
                    // { path: 'extendCheck/:id/:schoolId', component: cardExtendCheck, name: '查看发放记录' },
                ]
            },
            {
                path: '/cardCoupons/extendRecord',
                component: logiLayout,
                redirect: 'extendRecord/list',
                name: '卡券发放记录',
                noDropdown: true,
                children: [
                    { path: 'list', component: cardExtendRcord },
                    { path: 'extendCheck/:id/:schoolId', component: cardExtendCheck, name: '查看发放记录' },
                ]
            }
        ]
    }, {
        path: '/operation',
        redirect: '/operation/mainList',
        component: Layout,
        name: '广告管理',
        icon: 'zonghe',
        noDropdown: true,
        meta: {
            cache: 'operation'
        },
        children: [
            { path: 'mainList', component: operation },
            { path: 'parcelMangement', component: parcelMangement, name: '添加广告' },
            { path: 'getImgState', component: getImgState, name: '查看状态' },
            { path: 'advDisplay/:id', component: advDisplay, name: '查看广告' },
            { path: 'editAdv/:id', component: editAdv, name: '编辑广告' }
        ]
    },
    {
        path: '/memberMangement',
        component: Layout,
        redirect: '/memberMangement/memberMangement',
        name: '会员管理',
        icon: 'EXCEL',
        meta: {
            cache: 'memberMangement'
        },
        noDropdown: false,
        children: [
            { path: 'memberOrder', component: memberOrder, name: '会员订单' },
            { path: 'otherOrder', component: otherOrder, name: '学习礼包订单' },
            {
                path: '/packingOrder',
                component: logiLayout,
                redirect: 'memberMangement/packingOrder',
                name: '会员打包订单',
                noDropdown: true,
                children: [
                    { path: 'packingOrder', component: packingOrder},
                    { path: 'packingOrderDetail/:id?', component: packingOrderDetail, name: '会员打包订单详情' },
                ]
            },
            {
                path: '/memberMangement',
                component: logiLayout,
                redirect: '/memberMangement/activationCode',
                name: '激活码购买',
                noDropdown: true,
                children: [
                    { path: 'activationCode', component: codeManage },
                    { path: 'checkCode/:id?', component: checkvipDetails, name: '查看明细' },
                ]
            }
        ]
    },

    {
        path: '/account',
        component: Layout,
        redirect: '/account/accountMangement',
        name: '账户管理',
        icon: 'EXCEL',
        meta: {
            cache: 'accountMangement'
        },
        noDropdown: false,
        children: [{
                path: '/accountMangement',
                component: logiLayout,
                redirect: '/accountMangement/accountMangement',
                name: '账户信息',
                noDropdown: true,
                children: [
                    { path: 'accountMangement', component: accountMangement },
                    { path: 'checkDetails/:id?', component: checkDetails, name: '查看明细' },
                ]
            },
            {
                path: '/account',
                component: logiLayout,
                redirect: '/account/accountDetail',
                name: '银行卡信息',
                noDropdown: true,
                children: [
                    { path: 'accountDetail', component: accountDetail },
                    { path: 'makeAccount', component: makeAccount, name: '填写账户' },
                ]
            }
        ]
    },
    {
        path: '/reportForms',
        redirect: 'reportForms/totalTrend',
        component: Layout,
        icon: 'tubiaoleixingzhengchang',
        name: "统计报表",
        meta: {
            cache: 'schoolStatic,classStatic,teacherActivity,parentActivity,studentActivity'
        },
        noDropdown: false,
        children: [
            { path: 'totalTrend', component: totalTrend, name: '总体趋势' },
            { path: 'schoolStatic', component: schoolStatic, name: '学校用户统计' },
            // { path: 'classStatic', component: classStatic, name: '班级用户统计' },
            { path: 'teacherActivity', component: teacherActivity, name: '教师活跃度' },
            { path: 'parentActivity', component: parentActivity, name: '家长活跃度' },
            { path: 'studentActivity', component: studentActivity, name: '学生活跃度' }
        ]
    },
    {
        path: '/authority',
        redirect: 'authority/index',
        component: Layout,
        icon: 'quanxian',
        name: "权限管理",
        noDropdown: true,
        meta: {
            cache: 'authorityComponent'
        },
        children: [
            { path: 'index', component: authorityComponent, name: '权限管理' },
            { path: 'addAuthor', component: addAuthority, name: '添加权限' },
            { path: 'editAuthor/:pId', component: editAuthority, name: '修改权限' },
            { path: 'showAuthor/:pId', component: showAuthority, name: '查看权限' }
        ]
    },
    {
        path: '/attendance',
        redirect: 'attendance/index',
        component: Layout,
        icon: 'zujian',
        name: "考勤设备",
        meta: {
            cache: 'attendance'
        },
        noDropdown: true,
        children: [
            { path: 'attendance', component: attendance, name: '考勤设备' },
            { path: 'getAttendance/:id?', component: getAttendance, name: '查看考勤设备' }
        ]
    },
    {
        path: '/cardMain',
        redirect: 'cardMain/index',
        component: Layout,
        icon: 'zujian',
        name: "卡片管理",
        meta: {
            cache: 'cardMain'
        },
        noDropdown: true,
        children: [
            { path: 'index', component: cardMain, name: '卡片管理' }
        ]
    },
    { path: '*', redirect: '/404', hidden: true }
];